import Cookies from "js-cookie";

/*
 * localStorage 封装
 */
const localStorage = {
    // 设置
    setStorage(key: string, value: any) {
        window.localStorage.setItem(key, JSON.stringify(value));
    },
    // 获取
    getStorage(key: string) {
        const value = window.localStorage.getItem(key);
        if (value) {
            return JSON.parse(value);
        }
    },
    // 清空某一个
    deleteStorage(key: string) {
        window.localStorage.removeItem(key);
    },
    // 清空全部
    clearStorage() {
        window.localStorage.clear();
    },
};

/*
 * cookie 封装
 */
const cookies = {
    getCookie(key: string) {
        return Cookies.get(key);
    },
    setCookie(key: string, value: any) {
        Cookies.set(key, value);
    },
    removeCookie(key: string) {
        Cookies.remove(key);
        return;
    },
};

export { localStorage, cookies };
